<template>
    <div style="width: 100%;height: 600px;background-color: #fafafa">
        <div style="width:80%;height:600px;margin: auto">
            <div style="width: 600px;height: 600px;float: left">
                <div style="text-align: center;padding-top: 50px;">
                    <img width="500" height="500"  :src="priceList.img_url">
                </div>
            </div>
            <div style="width: 400px;height: 600px;float: right">
                <div style="width: 400px;height: 200px;margin-top:250px">
                    <div style="background-color: #C30932;width:50px;text-align: center;font-size: 14px;color: white">
                        -50%
                    </div>
                    <div style="font-size: 14px;color: #757575">
                        亚洲专属系列
                    </div>
                    <div style="font-size: 14px;margin-top: 3px">
                         {{priceList.goods_name}}
                    </div>
                    <div style="margin-top: 10px">
                        <span style="text-decoration:line-through;color:#757575">{{(parseInt(priceList.pice)).toFixed(2)}} ¥</span> <span style="color: #C30932">{{(parseInt(priceList.pice)*0.5).toFixed(2)}} ¥</span>
                    </div>
                    <div @click="shopAdd()" style="margin-top:20px;margin-left:80px;font-size:10px;background-color: black;color:white;height: 30px;width: 200px;text-align: center;padding-top: 10px;cursor: pointer;">
                        加入购物袋
                    </div>

                </div>
            </div>
        </div>
    </div>
</template>

<script>
    import {shopcarAddGoodsApi} from "@/api/lj_port/interface";

    export default {
        name: "detail",
        data(){
            return{
                priceList: {}
            }
        },
        methods:{

            //加入购物袋
            shopAdd(){
                if (sessionStorage.getItem('key')){
                    let pice = parseInt( this.priceList.pice)*0.5;
                    let date = new Date();
                    let user = sessionStorage.getItem('account');
                    let month = date.getMonth() + 1;
                    let time =date.getFullYear() + '年' + month + '月' + date.getDate() + '日'+date.getHours() +':' +date.getMinutes() ;
                    let row = {
                        "account":user,
                        "goods_id":this.priceList.id,
                        "goods_name":this.priceList.goods_name,
                        "select_number":1,
                        "goods_number":this.priceList.goods_stock,
                        "checked":0,
                        "goods_pice":pice,
                        "create_time":time ,
                        "updata_time":this.priceList.details,
                        "img_url":this.priceList.img_url
                    }
                    shopcarAddGoodsApi(row).then(() =>{
                        this.$message({type: 'success', message: '加入购物袋成功!'});
                        this.$router.go(0);
                    })
                }else {
                    this.$confirm('未登录, 是否跳转到登录页面?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'info'
                    }).then(() => {
                        this.$router.push({path:'/login'})
                    })
                }

            },
        },
        created() {
            if (this.$route.query){
                this.priceList =  JSON.parse(this.$route.query.dialogInfo);
            }
        },
        watch:{
            "$route.query.dialogInfo"(){
                this.priceList =  JSON.parse(this.$route.query.dialogInfo);
            },
        },
    }
</script>

<style scoped>

</style>
